/**
 * 题目链接：2025/11/12 考试 T4 隔膜
 * 完成时间：2025/11/12 12:15
 * 简要思路：20pts：矩形性质。
 */
#include <bits/stdc++.h>
#define range(i, b, e) for (auto i(b); i != (e); i++)
#define rep(i, b, e) for (auto i(b); i <= (e); i++)
#define req(i, b, e) for (auto i(b); i >= (e); i--)
using namespace std;
typedef long long LL;
typedef pair<int, int> Pii;

const int N = 5e5;
int n;
pair<int, int> p[N+5];

LL checksqu() {
	int minx = 1e9, miny = 1e9, maxx = 0, maxy = 0;
	rep(i, 1, n) {
		minx = min(minx, p[i].first);
		miny = min(miny, p[i].second);
		maxx = max(maxx, p[i].first);
		maxy = max(maxy, p[i].second);
	}
	LL h = maxx - minx + 1, c = maxy - miny + 1;
	if (h * c != n) return -1;
	LL ansh = 0, ansc = 0;
	rep(i, 1, h) ansc += LL(i-1) * i / 2 + LL(h-i) * (h-i+1) / 2;
	rep(i, 1, c) ansh += LL(i-1) * i / 2 + LL(c-i) * (c-i+1) / 2;
	return ansh * h + ansc * c;
}

int main() {
	freopen("game.in", "r", stdin);
	freopen("game.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	cin >> n;
	rep(i, 1, n) cin >> p[i].first >> p[i].second;
	LL ans = checksqu();
	if (~ans) {
		cout << ans;
		return 0;
	}
	return 0;
}
